package Euler39;

import java.util.*;

public class IntegralRightTriangles {
	public static void main(String[] args) {
		long max = 0, maxHolder = 0; 
		HashMap<Long, long[]> vals;
		
		for(int i = 3; i <= 1000; i++){
			vals = getIntegralSides(i);
			if(vals.size()>max)
			{
				max = vals.size();
				maxHolder = i;
			}
		}
		
		System.out.println(max);
		System.out.println(maxHolder);
		
		/*
		Set<Long> hyps = vals.keySet();
		Iterator<Long> iter = hyps.iterator();
		while(iter.hasNext())
		{
			long c = iter.next();
			System.out.print(c + " ");
			long sides[] = vals.get(c);
			
			for(int j = 0; j < sides.length; j++)
			{
				System.out.print(sides[j] + " ");
			}
			
			System.out.println();
		}*/
	}
	
	static HashMap<Long, long[]> getIntegralSides(int perimeter)
	{
		HashMap<Long, long[]> sides = new HashMap<Long, long[]>();
		
		for(int i = 1; i < perimeter; i++)
		{
			int leftover = perimeter - i;
					
			for(int j = 1; j < leftover; j++)
			{
				int a,b,c;
				
				a = i;
				b = j;
				c = perimeter - (a+b);
				
				if(a>c)
				{
					int temp = a;
					a=c;
					c = temp;
				}
				if(b>c)
				{
					int temp = b;
					b=c;
					c = temp;
				}
				
				if(((a*a) + (b*b)) == (c*c))
				{
					sides.put((long)c, new long[]{a, b});
				}
			}
		}
		
		/*int max = (perimeter/4)+1;
		for(int i = 0; i < max; i++)
		{
			int a = i;
			int b = (perimeter/2)-i;
			int c = perimeter - (a + b);
			
			if(((a*a) + (b*b)) == (c*c))
			{
				sides.add(new long[]{a, b, c});
			}
		}*/
		
		return sides;
	}
}
